package can;

/**
 * Encapsulates X and Y coordinates as doubles.
 * 
 * @author Andrea
 * 
 */
public class ConnellBotPoint {
  private double x;
  private double y;

  /**
   * Initialize this point's X and Y coordinates.
   * 
   * @param x X-coordinate
   * @param y Y-coordinate
   */
  ConnellBotPoint(double x, double y) {
    this.x = x;
    this.y = y;
  }

  /**
   * Returns this point's X-coordinate.
   * 
   * @return X-coordinate
   */
  double getX() {
    return this.x;
  }

  /**
   * Returns this point's Y-coordinate.
   * 
   * @return Y-coordinate
   */
  double getY() {
    return this.y;
  }

  /**
   * The new X-coordinate.
   * 
   * @param x X-coordinate
   */
  void setX(double x) {
    this.x = x;
  }

  /**
   * The new Y-coordinate.
   * 
   * @param y Y-coordinate
   */
  void setY(double y) {
    this.y = y;
  }

  /**
   * Determines whether two DoublePoints are equal by comparing their X and Y coordinates.
   * 
   * @param o Object to compare this point to
   * @return True if the x and y coordinates of each point are the same.
   */
  @Override
  public boolean equals(Object o) {
    if (!(o instanceof ConnellBotPoint)) {
      return false;
    }
    ConnellBotPoint p = (ConnellBotPoint) o;
    // don't care about rounding errors
    return (int) p.getX() == (int) this.x && (int) p.getY() == (int) this.y;
  }

  /**
   * Generates hash code based on the values of the X and Y coordinates.
   * 
   * @return Hashcode calculated from X and Y
   */
  @Override
  public int hashCode() {
    return (int) ((this.x * 13) + (this.y * 11));
  }

  /**
   * Returns the point represented as a string.
   * 
   * @return A string in the form "x, y"
   */
  @Override
  public String toString() {
    return this.x + ", " + this.y;
  }
}
